* DERMATOLOGIA  

use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="DERMATOLOGIA"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CLINICA MEDICA"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0)) ///
xline(2001, lcolor(red) lp(solid))  xline(2005, lcolor(red) lp(dash)) ///
text(0.05 2003 "Phase-in") text(0.05 2007 "Repeal")  ///
xsc(range(1994 2021)) ytitle("Share of dermatologists with training in" "internal medicine") ///
xtitle(" " "Enrollment year in Dermatology")  title("Panel E. Dermatology", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_Dermatology.pdf", replace 


* Cardiology 
use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="CARDIOLOGIA"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CLINICA MEDICA"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0)) ///
xline(2001, lcolor(red) lp(solid))  xline(2005, lcolor(red) lp(dash)) ///
text(0.5 2003 "Phase-in") ///
xsc(range(1994 2021)) ytitle("Share of cardiologists with training in" "internal medicine") ///
xtitle(" " "Enrollment year in Cardiology")  title("Panel A. Cardiology", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_cardiology.pdf", replace 


*CIRURGIA VASCULAR SURGERY 
use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="CIRURGIA VASCULAR"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CIRURGIA GERAL"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0))    ///
xsc(range(1994 2021)) ytitle("Share of vascular surgeones with training in" "General Surgery") ///
xtitle(" " "Enrollment year in Vascular Surgery") text(0.55 2002.5 "Phase-in", size(small))  title("Panel B.") ///
xline(2001, lcolor(red) lp(solid))  xline(2004, lcolor(red) lp(dash)) title("Panel B. Vascular Surgery", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_vascular_surgery.pdf", replace 

*NEFROLOGIA 
use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="NEFROLOGIA"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CLINICA MEDICA"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0))    ///
xsc(range(1994 2021)) ytitle("Share of nephrologists with training in" "internal medicine") ///
text(0.25 2003 "Phase-in") ///
xtitle(" " "Enrollment year in Nephrology")  ///
xline(2001, lcolor(red) lp(solid))  xline(2005, lcolor(red) lp(dash)) title("Panel C. Nephrology", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_nephrology.pdf", replace 


*GASTROENTEROLOGIA
use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="GASTROENTEROLOGIA"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CLINICA MEDICA"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0)) xline(2001, lcolor(red) lp(solid))  xline(2005, lcolor(red) lp(dash)) ///
xsc(range(1994 2021)) ytitle("Share of gastroenterologists with training in" "Internal Medicine") ///
xtitle(" " "Enrollment year in Gastroenterology ") text(0.5 2003 "Phase-in")  title("Panel D. Gastroenterology", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_Gastroenterology.pdf", replace 


* Neurology 
use "${Gpath}data\\cnrm_2021.dta", clear 

keep cpf inicio programa
drop if cpf=="############"
drop if cpf=="99999999999"
drop if cpf==""

gen X=programa=="NEUROLOGIA"
bysort cpf: egen cardiology=max(X)
drop X 

gen X=programa=="CLINICA MEDICA"
bysort cpf: egen internal=max(X)
drop X 

bysort cpf: keep if _n==1 

gen entry_year=substr(inicio, -4, .)
destring entry_year, replace 

keep if cardiology==1 
keep if entry_year>=1995 & entry_year<=2019
collapse (mean) internal, by(entry_year)

line internal entry_year, graphregion(color(white) margin(0))    ///
xsc(range(1994 2021)) ytitle("Share of neurologist with training in" "internal medicine") ///
xtitle(" " "Enrollment year in Neurology") ///
text(0.05 2003 "Phase-in") text(0.05 2006.5 "Repeal") ///
xline(2001, lcolor(red) lp(solid))  xline(2005, lcolor(red) lp(dash)) title("Panel E. Neurology", pos(11) size(medium))

graph export "${Gpath}\figures\\reform_Neurology.pdf", replace 
